package com.ys.day29.Reflect.p10反射的坑与总结;

import java.lang.reflect.Method;
import java.util.ArrayList;

/**
 * 描述:
 *   getMethods() 与 getDeclaredMethods() 的区别
 *   getMethods 只能获得 类对象的 公有方法签名+父类的公有方法签名
 *   getDeclaredMethods 获得当前 类对象的所有的方法签名,包括 public private 默认 , protected
 *   总结:
 *   1:没加Declared 就是获得当前类+父类的 所有公共 方法|属性
 *   2:加了Declared 就是获得当前类的 所有 方法|属性
 *
 * @author CodeYang
 * @version 2021/1/11 23:43
 */
public class P1反射的坑 {

    public static void main(String[] args) {
     // function01();
      function02();
    }

    /**
     *  getDeclaredMethods 获得当前 类对象的所有的方法签名,包括 public private 默认 , protected
     */
    private static void function02() {
        Class<ArrayList> aClass = ArrayList.class;

        Method[] methods = aClass.getDeclaredMethods();
        for (Method method : methods) {
            System.out.println(method);
        }
        /**
         *
         * public void java.util.ArrayList.add(int,java.lang.Object)
         * public boolean java.util.ArrayList.add(java.lang.Object)
         * public boolean java.util.ArrayList.remove(java.lang.Object)
         * public java.lang.Object java.util.ArrayList.remove(int)
         * public java.lang.Object java.util.ArrayList.get(int)
         * public java.lang.Object java.util.ArrayList.clone()
         * public int java.util.ArrayList.indexOf(java.lang.Object)
         * public void java.util.ArrayList.clear()
         * public boolean java.util.ArrayList.contains(java.lang.Object)
         * public boolean java.util.ArrayList.isEmpty()
         * public java.util.Iterator java.util.ArrayList.iterator()
         * public int java.util.ArrayList.lastIndexOf(java.lang.Object)
         * public void java.util.ArrayList.replaceAll(java.util.function.UnaryOperator)
         * public int java.util.ArrayList.size()
         * public java.util.List java.util.ArrayList.subList(int,int)
         * public java.lang.Object[] java.util.ArrayList.toArray()
         * public java.lang.Object[] java.util.ArrayList.toArray(java.lang.Object[])
         * public java.util.Spliterator java.util.ArrayList.spliterator()
         * public boolean java.util.ArrayList.addAll(int,java.util.Collection)
         * public boolean java.util.ArrayList.addAll(java.util.Collection)
         * static int java.util.ArrayList.access$000(java.util.ArrayList)
         * private void java.util.ArrayList.readObject(java.io.ObjectInputStream) throws java.io.IOException,java.lang.ClassNotFoundException
         * private void java.util.ArrayList.writeObject(java.io.ObjectOutputStream) throws java.io.IOException
         * public void java.util.ArrayList.forEach(java.util.function.Consumer)
         * public java.lang.Object java.util.ArrayList.set(int,java.lang.Object)
         * public void java.util.ArrayList.ensureCapacity(int)
         * public void java.util.ArrayList.trimToSize()
         * private void java.util.ArrayList.ensureCapacityInternal(int)
         * private static int java.util.ArrayList.hugeCapacity(int)
         * java.lang.Object java.util.ArrayList.elementData(int)
         * private void java.util.ArrayList.grow(int)
         * public java.util.ListIterator java.util.ArrayList.listIterator(int)
         * public java.util.ListIterator java.util.ArrayList.listIterator()
         * public boolean java.util.ArrayList.removeAll(java.util.Collection)
         * public boolean java.util.ArrayList.removeIf(java.util.function.Predicate)
         * protected void java.util.ArrayList.removeRange(int,int)
         * public boolean java.util.ArrayList.retainAll(java.util.Collection)
         * public void java.util.ArrayList.sort(java.util.Comparator)
         * private java.lang.String java.util.ArrayList.outOfBoundsMsg(int)
         * private void java.util.ArrayList.rangeCheckForAdd(int)
         * private boolean java.util.ArrayList.batchRemove(java.util.Collection,boolean)
         * private static int java.util.ArrayList.calculateCapacity(java.lang.Object[],int)
         * private void java.util.ArrayList.ensureExplicitCapacity(int)
         * private void java.util.ArrayList.fastRemove(int)
         * private void java.util.ArrayList.rangeCheck(int)
         * static void java.util.ArrayList.subListRangeCheck(int,int,int)
         *
         */
    }

    /**
     * getMethods 只能获得 类对象的 公有方法签名+父类的公有方法签名
     */
    private static void function01() {
        Class<ArrayList> aClass = ArrayList.class;

        Method[] methods = aClass.getMethods();
        for (Method method : methods) {
            System.out.println(method);
        }
        /**
         *  输出了 当前类+父类的所有的 公共方法
         * public void java.util.ArrayList.add(int,java.lang.Object)
         * public boolean java.util.ArrayList.add(java.lang.Object)
         * public boolean java.util.ArrayList.remove(java.lang.Object)
         * public java.lang.Object java.util.ArrayList.remove(int)
         * public java.lang.Object java.util.ArrayList.get(int)
         * public java.lang.Object java.util.ArrayList.clone()
         * public int java.util.ArrayList.indexOf(java.lang.Object)
         * public void java.util.ArrayList.clear()
         * public boolean java.util.ArrayList.contains(java.lang.Object)
         * public boolean java.util.ArrayList.isEmpty()
         * public java.util.Iterator java.util.ArrayList.iterator()
         * public int java.util.ArrayList.lastIndexOf(java.lang.Object)
         * public void java.util.ArrayList.replaceAll(java.util.function.UnaryOperator)
         * public int java.util.ArrayList.size()
         * public java.util.List java.util.ArrayList.subList(int,int)
         * public java.lang.Object[] java.util.ArrayList.toArray()
         * public java.lang.Object[] java.util.ArrayList.toArray(java.lang.Object[])
         * public java.util.Spliterator java.util.ArrayList.spliterator()
         * public boolean java.util.ArrayList.addAll(int,java.util.Collection)
         * public boolean java.util.ArrayList.addAll(java.util.Collection)
         * public void java.util.ArrayList.forEach(java.util.function.Consumer)
         * public java.lang.Object java.util.ArrayList.set(int,java.lang.Object)
         * public void java.util.ArrayList.ensureCapacity(int)
         * public void java.util.ArrayList.trimToSize()
         * public java.util.ListIterator java.util.ArrayList.listIterator(int)
         * public java.util.ListIterator java.util.ArrayList.listIterator()
         * public boolean java.util.ArrayList.removeAll(java.util.Collection)
         * public boolean java.util.ArrayList.removeIf(java.util.function.Predicate)
         * public boolean java.util.ArrayList.retainAll(java.util.Collection)
         * public void java.util.ArrayList.sort(java.util.Comparator)
         * public boolean java.util.AbstractList.equals(java.lang.Object)
         * public int java.util.AbstractList.hashCode()
         * public java.lang.String java.util.AbstractCollection.toString()
         * public boolean java.util.AbstractCollection.containsAll(java.util.Collection)
         * public final void java.lang.Object.wait() throws java.lang.InterruptedException
         * public final void java.lang.Object.wait(long,int) throws java.lang.InterruptedException
         * public final native void java.lang.Object.wait(long) throws java.lang.InterruptedException
         * public final native java.lang.Class java.lang.Object.getClass()
         * public final native void java.lang.Object.notify()
         * public final native void java.lang.Object.notifyAll()
         * public default java.util.stream.Stream java.util.Collection.stream()
         * public default java.util.stream.Stream java.util.Collection.parallelStream()
         */
    }

}
